#ifndef FORMSOCKETSRV_H
#define FORMSOCKETSRV_H

#include <QWidget>
#include <QtNetwork>
#include "ctrlMouse.h"
#include "defines.h"

namespace Ui {
class FormSocketSrv;
}

class FormSocketSrv : public QWidget
{
    Q_OBJECT
    
public:
    explicit FormSocketSrv(QWidget *parent = 0, int socketType = 0);
    ~FormSocketSrv();

    void showHostIP();

    bool isCompletePacket(QByteArray byteArray);
    void processPakcet(QByteArray byteArray);
    void handlePakcet(QByteArray byteArray);

    void startServer(bool state);

signals:
    void sigCtrlMouse(QByteArray array);
    void sigSrvStateChanged(bool state);

private slots:
    void on_btnStart_clicked();

    //udp
    void slotReadUdpData();

    //tcp
    void slotConnectClient();

    void slotDisconnected();

    void slotReadTcpData();


private:
    Ui::FormSocketSrv *ui;

    QUdpSocket *m_pUdpSocket;   //udp socket

    QTcpServer *m_pTcpServer;   //server tcp socket
    QTcpSocket *m_pConnectSocket;      //client connect socket

    int m_nSocketType;  //0:udp;    1:tcp;
    int m_nPort;

    QByteArray m_barrPacket;
    int m_nPackIndex;
    int m_nPackLength;
    int m_nPackChecksum;

    ctrlMouse *m_pCtrlMouse;
};

#endif // FORMSOCKETSRV_H
